package com.kcht.itsed.mws.persist.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.kcht.itsed.mws.alemodel.TMSpec;
import com.kcht.itsed.mws.extendalemodel.PRSpec;
import com.kcht.itsed.mws.extendmodel.jpa.SpecEntityConverter;
import com.kcht.itsed.mws.extendmodel.jpa.TagMemoryEntity;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.type.JdbcType;

import java.util.List;
import java.util.Optional;

/**
 * 标签区规则持久层
 * @author zhangwenshuo
 *
 */
public interface ITagMemoryDao extends BaseMapper<TagMemoryEntity> {

	@Select("select * from T_TAG_MEMORY where TM_NAME=#{specName}")
	@Results(
			@Result(
					column = "TM_SPEC",
					property = "tmSpec",
					javaType = TMSpec.class,
					jdbcType = JdbcType.VARCHAR,
					typeHandler = SpecEntityConverter.class
			)
	)
	Optional<TagMemoryEntity> findBySpecName(String specName);

	@Delete("delete from T_TAG_MEMORY where TM_NAME=#{specName}")
	void dropTagMemoryEntity(String specName);

	@Select("select TM_NAME from T_TAG_MEMORY")
	List<String> queryTagMemory();

	@Select("select * from T_TAG_MEMORY")
	@Results(
			@Result(
					column = "TM_SPEC",
					property = "tmSpec",
					javaType = TMSpec.class,
					jdbcType = JdbcType.VARCHAR,
					typeHandler = SpecEntityConverter.class
			)
	)
	List<TagMemoryEntity> loadAllTagMemoryEntities();
	
}
